#ifndef HASH_TABLE_HPP_
#define	HASH_TABLE_HPP_

#include <exception>
#include "list.hpp"
#include "utils.hpp"
#include "game.hpp"
#include <math.h>

class HashTableException : public std::exception {};
class ElementAlreadyInTableException: public HashTableException{};
class ElementNotInTableException: public HashTableException{};

/**
 * HashTable:
 * A  hash table with integer keys, designed to hold game objects.
 */
class HashTable{
private:
	List<Game>* arrayOfLists;
	int arraySize;
	int gamesCounter;
	static const double hashConst; 

    int _hashFunction(int k) const;
    void _rehash(List<Game>* oldArray, int oldArraySize);
    void _addToTable(const Game& game);
    void _resizeUp();
    void _resizeDown(); 
	void _removeFromTable(int key);
    bool  _entryIsEmpty(int index) const;
    bool  _entryIsEmpty(List<Game>* myArrayOfLists, int index) const;
	
public:
	/**
	 * C'tor & D'tor
	 */
	HashTable(int initialSize); 
	~HashTable(); 
	
    void insert(const Game& game);
	void remove(int key);
	const Game* find(int key) const;
	bool isMember(int key) const;
};


#endif /* HASH_TABLE_HPP_ */
